package cn.wsn2018.tools.ctrl;

import cn.wsn2018.tools.service.IDCodeService;
import cn.wsn2018.tools.util.ServletUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类名称:CodeController
 * 类描述:TODO
 * 创建人:nzx
 * 创建时间:2019/8/6 15:35
 */


@RestController
@RequestMapping("/protocol")
public class IDCodeController {

    @Autowired
    private IDCodeService iDCodeService;

    @CrossOrigin
    @RequestMapping(value = "/IDCode",method = RequestMethod.GET)
    /**
     * 生成验证码
     */
    public String makeIDCode(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ServletUtil.getInstance().requestOperating(request);
        String respJson = iDCodeService.makeIDCode(request);
        ServletUtil.getInstance().responseOperating(response, respJson);
        return null;
    }


    @CrossOrigin
    @RequestMapping(value = "/checkIDCode",method = RequestMethod.GET)
    /**
     * 校验验证码
     */
    public String checkIDCode(@RequestParam("code") String code,HttpServletRequest request, HttpServletResponse response) throws Exception {
        ServletUtil.getInstance().requestOperating(request);
        String respJson = iDCodeService.checkIDCode(code,request);
        ServletUtil.getInstance().responseOperating(response, respJson);
        return null;
    }

}
